from . import ConnectMysql

class ApiSql(ConnectMysql):

    def insert_login_info(self,phone,password):
        
        SQL='INSERT INTO account (phone,pass_word) VALUES (%s,%s)'
        result=self.insert_info(SQL,(phone,password))
       
        return result

    def select_verify_code(self,verify_code,phone):

        # SQL='select * from verify_code where id=(select MAX(id) from verify_code ) and verify_code=%s'
        SQL='select * from phone_verify where verify_code =%s and phone=%s'

        result=self.select_one(SQL,(verify_code,phone))

        return result
    def select_code(self,phone,verify_code):

        SQL='select * from phone_verify where id=(select MAX(id) from phone_verify where phone=%s) and verify_code=%s'

        result=self.select_one(SQL,(phone,verify_code))

        return result

    def select_user_info(self,phone):

        SQL='SELECT * FROM account where phone=%s'

        result=self.select_one(SQL,(phone,))

        return result

    def select_login_info(self,phone,pass_word):
        
        SQL='SELECT * FROM account where phone=%s and pass_word=%s'

        result=self.select_one(SQL,(phone,pass_word))

        return result

    def update_login_password(self,phone,password):

        SQL='UPDATE account SET pass_word=%s WHERE phone = %s'

        result=self.update_info(SQL,(password,phone))

        return result
        
    def insert_verify_code(self,verify_code,phone):

        SQL='INSERT INTO phone_verify (verify_code,phone) VALUES (%s,%s)'
        
        result=self.insert_info(SQL,(verify_code,phone))

        return result

    def compare_phone(self,phone):
        compare_sql = '''
        select * from account where phone = %s
        '''
        result = self.select_one(compare_sql,(phone,))
        return result

